package cc.web.vaaking.servlet.system;

import cc.web.vaaking.common.LoginContext;
import cc.web.vaaking.common.LoginUser;
import cc.web.vaaking.entity.SysUser;
import cc.web.vaaking.services.SysUserService;
import cc.web.vaaking.servlet.BaseHttpServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "HomeServlet",value = "/home/*")
public class HomeServlet extends BaseHttpServlet {


    SysUserService sysUserService = new SysUserService();

    @Override
    public void init() throws ServletException {
        routerMap.put("index", this::index);
        routerMap.put("welcomePage",this::welcomePage);
    }

    private void welcomePage(HttpServletRequest request, HttpServletResponse response) {
        try {
            request.getRequestDispatcher("../views/system/welcome.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    private void index(HttpServletRequest request, HttpServletResponse response) {
        try {
            LoginUser user = LoginContext.getCurrentUser();
            request.getRequestDispatcher("../views/system/home.jsp").forward(request,response);
        } catch (ServletException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}
